package laf.learning;

import java.util.Collection;
import java.util.Collections;

import laf.agents.LanguageSymbolDictionary;
import laf.env.Attribute;
import laf.env.AttributeDomain;
import laf.env.AttributeValue;
import laf.env.Enviroment;
import laf.env.State;
import laf.lang.Symbol;

public class GroundingStrategyImpl extends AbstractGroundingStrategy {
	
	public GroundingStrategyImpl(GroundingRule groundingRule) {
		super(groundingRule);
	}

	@Override
	public void updateCorrelation(LanguageSymbolDictionary dictionary, Symbol symbol, State state) {
		Attribute attr;
		double correlation;
		long credibility;
		for (AttributeValue attrValue : state.getValues()) {
			attr = Enviroment.getInstance().getAttribute(attrValue.getAttributeIdentifier());
			for (AttributeValue v : attr.getValues()) {
				correlation = dictionary.getCorrelation(symbol, v);
				credibility = dictionary.getCredibility(symbol, v);
				if (v.equals(attrValue)) {
					correlation = groundingRule.increaseCorrelation(correlation, credibility);
				} else {
					correlation = groundingRule.decreaseCorrelation(correlation, credibility);
				}
				dictionary.setCorrelation(symbol, v, correlation);
				dictionary.setCredibility(symbol, v, ++credibility);
			}
		}

	}

}
